


tartget=input()
source=input()
def getResult():
    current_index=len(tartget)-1
    for i in range(len(source)-1,-1,-1):
        if source[i]==tartget[current_index]:
            current_index=current_index-1
            if current_index<0:
                return i
    return -1

print(getResult())